package com.example.rest;

import com.example.ccubee.common.vo.ResultVo;
import com.example.service.TestService;
import com.example.service.TestServiceDb;
import com.example.service.TestServiceRedis;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ccubee
 * @since 2021/8/26 19:51
 */
@RestController
@RequestMapping
@RequiredArgsConstructor
public class TestRest {

    private final TestService testService;
    private final TestServiceRedis testServiceRedis;
    private final TestServiceDb testServiceDb;

    @GetMapping("test")
    public ResultVo<String> test(@RequestParam String userId, Long projectId) {
        testService.test(userId, projectId);
        return ResultVo.success("秒杀成功");
    }

    @GetMapping("testRedis")
    public ResultVo<String> testRedis(@RequestParam String userId, Long projectId) {
        System.out.println("秒杀开始===》");
        testServiceRedis.test(userId, projectId);
        return ResultVo.success("秒杀成功");
    }

    @GetMapping("testDb")
    public ResultVo<String> testDb(@RequestParam String userId, Long projectId) {
        System.out.println("秒杀开始===》");
        testServiceDb.test(userId, projectId);
        return ResultVo.success("秒杀成功");
    }
}
